#include "common_service.h"
#include <stdexcept>

namespace infrastructure {
namespace services {

CommonService::CommonService(
    std::shared_ptr<infrastructure::factories::LoggerFactory> loggerFactory,
    std::shared_ptr<kernel::IConfiguration> configService)
    : m_loggerFactory(loggerFactory)
    , m_configService(configService)
{
    if (!m_loggerFactory) {
        throw std::invalid_argument("CommonService: LoggerFactory不能为空");
    }

    if (!m_configService) {
        throw std::invalid_argument("CommonService: 配置服务不能为空");
    }

    // 使用默认logger记录初始化信息
    auto defaultLogger = m_loggerFactory->getDefaultLogger();
    if (defaultLogger) {
        defaultLogger->info("CommonService 初始化完成 - 聚合日志工厂和配置服务");
    }
}

std::shared_ptr<kernel::ILogger> CommonService::getLogger(const std::string& loggerName) const
{
    return m_loggerFactory->getLogger(loggerName);
}

} // namespace services
} // namespace infrastructure